const mysql = require('mysql')

const db = mysql.createPool({
    host: '10.161.12.98',
    port: '3386',
    user: 'tydyl',
    password: 'E9@13$z4gf*',
    database: 'tydylchaifenjgyj'
})

// db.query('select 1', (err, results) => {
//     if(err) return console.log(err.message)

//     console.log(results)
// })


// 查询
// const sql = 'select * from novel_test'

// db.query(sql, (err, results) => {
//     if (err) return console.log(err.message)

//     console.log(results)
// })


// 插入
const sql_insert = 'insert into novel_test(title, content) values (?, ?)'
// const sql_insert = 'insert into novel_test set ?)'

db.query(sql_insert, ['npm', 'node'], (err, results) => {
    if (err) return console.log(err.message)

    console.log(results)

    if (results.affectedRows === 1){
        console.log('数据插入成功！')
    }
})


